﻿using UnityEditor;

namespace Editor.Tools
{
    public static class DefineSymbolsManager
    {
        private static void SetMacroEnable(string macro)
        {
            var group = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
            var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
            if (defines.Contains(macro))
            {
                return;
            }
            defines += ";" + macro;
            PlayerSettings.SetScriptingDefineSymbolsForGroup(group, defines);
        }

        private static void SetMacroDisable(string macro)
        {
            var group = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget);
            var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
            defines = defines.Replace(macro, "");
            PlayerSettings.SetScriptingDefineSymbolsForGroup(group, defines);
        }
        
        
        [MenuItem("Tools/Macro/Enable PRINT_MSG(启用协议打印日志)")]
        public static void EnableMyCustomDefine()
        {
            SetMacroEnable("PRINT_MSG");
        }

        [MenuItem("Tools/Macro/Disable PRINT_MSG(禁用协议打印日志)")]
        public static void DisableMyCustomDefine()
        {
            SetMacroDisable("PRINT_MSG");
        }
        
    }
}